package com.spring.sunflower.dialog

import android.content.Context
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.lxj.xpopup.core.CenterPopupView
import com.spring.sunflower.R
import com.spring.sunflower.bean.NewGiftBagBean
import com.spring.sunflower.util.DisplayUtils

/**
 * Created by Kevin on 2021/8/6<br/>
 *
 * Describe:<br/>
 *新手礼包
 */
class NewGiftDialog(
    context: Context,
    var layoutID: Int,
) : CenterPopupView(context) {
    private var tvGift: TextView? = null
    private var tvDone: TextView? = null
    private var llDone: LinearLayout? = null
    override fun getImplLayoutId(): Int {
        return layoutID
    }

    override fun onCreate() {
        super.onCreate()
        llDone = findViewById(R.id.llDone)
        tvDone = findViewById(R.id.tvDone)
        tvGift = findViewById(R.id.tvGift)
        val ivClose = findViewById<ImageView>(R.id.ivClose)
        ivClose.setOnClickListener { dismiss() }
        listener?.onCreateView()
        llDone?.setOnClickListener {
            listener?.onGetNewGift()
            dismiss()
        }
    }

    private var listener: OnNewGiftListener? = null
    fun setOnNewGiftListener(l: OnNewGiftListener) {
        listener = l
    }

    interface OnNewGiftListener {
        fun onCreateView()
        fun onGetNewGift()
    }

    fun setGift(data: NewGiftBagBean.DatasBean) {
        if (data.coupon.toInt() > 0) {
            tvGift!!.text = "「视频畅聊」"
        }
        if (data.goldCoin.toInt() > 0) {
            if (!tvGift!!.text.isNullOrEmpty()) {
                val text = tvGift!!.text
                tvGift!!.text = "${text}，金币x${data.goldCoin}"
            } else {
                tvGift!!.text = "金币x${data.goldCoin}"
            }
        }
    }

    override fun getMaxWidth(): Int {
        return (DisplayUtils.getScreenWidth(context) * 1).toInt()
    }

}